// src/monaco/theme-dsql.ts
import type * as Monaco from 'monaco-editor'

export function defineDsqlThemes(monaco: typeof import('monaco-editor')) {
    // 深色主题
    monaco.editor.defineTheme('dsql-dark', {
        base: 'vs-dark',
        inherit: true,
        rules: [
            // 你在 dsql.ts 里用到的 token 名：keyword/operator/string/number/comment/delimiter/variable/macro/function/predefined/identifier
            { token: 'keyword',    foreground: 'FFB454', fontStyle: 'bold' }, // if: / for: 行、SQL 关键字
            { token: 'operator',   foreground: 'C792EA' },
            { token: 'string',     foreground: 'A5E844' },
            { token: 'number',     foreground: 'F78C6C' },
            { token: 'comment',    foreground: '5C6370', fontStyle: 'italic' },
            { token: 'delimiter',  foreground: '89DDFF' },
            { token: 'variable',   foreground: 'E2B93D' }, // ${...}
            { token: 'macro',      foreground: '82AAFF' }, // #{...}
            { token: 'function',   foreground: '82AAFF' }, // 其他函数名
            { token: 'predefined', foreground: 'C3E88D' }, // 内置函数（length/trim…）与 SQL 函数
            { token: 'identifier', foreground: 'FFFFFF' }, // 普通标识符（列、变量等）
        ],
        colors: {
            'editor.background':                '#0F111A', // ⭐ 背景
            'editor.foreground':                '#E6E6E6',
            'editorLineNumber.foreground':      '#4B5263',
            'editorLineNumber.activeForeground':'#D19A66',
            'editorCursor.foreground':          '#AEAFAD',
            'editor.selectionBackground':       '#264F78',
            'editor.inactiveSelectionBackground':'#264F7833',
            'editor.lineHighlightBackground':   '#FFFFFF0A',
            'editorIndentGuide.background':     '#3B3F51',
            'editorIndentGuide.activeBackground':'#8A919966',
            'editorGutter.background':          '#0F111A',
            'editorSuggestWidget.background':   '#1E222A',
            'editorSuggestWidget.foreground':   '#D0D4DB',
            'editorSuggestWidget.highlightForeground': '#FFB454',
            'editorSuggestWidget.selectedBackground':  '#2A2F3A',
            'editorBracketMatch.border':        '#FFD70088',
        },
    })

    // 浅色主题（可选）
    monaco.editor.defineTheme('dsql-light', {
        base: 'vs',
        inherit: true,
        rules: [
            { token: 'keyword',    foreground: '9C27B0', fontStyle: 'bold' },
            { token: 'operator',   foreground: '6A1B9A' },
            { token: 'string',     foreground: '2E7D32' },
            { token: 'number',     foreground: 'C62828' },
            { token: 'comment',    foreground: '9E9E9E', fontStyle: 'italic' },
            { token: 'delimiter',  foreground: '1976D2' },
            { token: 'variable',   foreground: 'B26A00' },
            { token: 'macro',      foreground: '1565C0' },
            { token: 'function',   foreground: '1565C0' },
            { token: 'predefined', foreground: '2E7D32' },
            { token: 'identifier', foreground: '000000' },
        ],
        colors: {
            'editor.background':                '#FFFFFF', // ⭐ 背景
            'editor.foreground':                '#1F2328',
            'editorLineNumber.foreground':      '#9E9E9E',
            'editorLineNumber.activeForeground':'#616161',
            'editorCursor.foreground':          '#333333',
            'editor.selectionBackground':       '#CCE5FF',
            'editor.inactiveSelectionBackground':'#CCE5FF66',
            'editor.lineHighlightBackground':   '#0000000D',
            'editorIndentGuide.background':     '#E0E0E0',
            'editorIndentGuide.activeBackground':'#BDBDBD',
            'editorGutter.background':          '#FFFFFF',
            'editorSuggestWidget.background':   '#FFFFFF',
            'editorSuggestWidget.foreground':   '#1F2328',
            'editorSuggestWidget.highlightForeground': '#9C27B0',
            'editorSuggestWidget.selectedBackground':  '#E3F2FD',
            'editorBracketMatch.border':        '#9C27B0AA',
        },
    })
}
